
# Imports
import pickle
import base64
import time

# Object representing a snapshot
class snapshot:

	# Constructor
	def __init__(self):
	
		# Set vars
		self.version = 0
		self.cno = 0
		self.uuid = ""
		self.timestamp = None
		
	# Set the timestamp to the current time
	def SetTimestampNow(self):
		self.timestamp = time.localtime()
	
	# Format the timestamp as a string
	def GetTimestampString(self):
		return time.strftime("%Y-%m-%d %H:%M:%S %Z", self.timestamp)
	
	# Set the timestamp from a string
	def SetTimestampFromString(self, tstampString):
		
		# Parse the time
		self.timestamp = time.strptime(tstampString, "%Y-%m-%d %H:%M:%S %Z")
	
# Pickles a snapshot and then base64 encodes it
def PickleSnapshot(ss):
	
	# Pickle
	pickledSS = pickle.dumps(ss)
	
	# Base64 encode
	pickledSSBase64 = base64.urlsafe_b64encode(pickledSS)
	
	# Return
	return pickledSSBase64

# Base64 decodes a snapshot and then unpickles it
def UnPickleSnapshot(pickledSSBase64):
	
	# Base64 decode
	pickledSS = base64.urlsafe_b64decode(pickledSSBase64)
	
	# Unpickle
	ss = pickle.loads(pickledSS)
	
	# Return
	return ss
